<html>
<head><meta charset="utf-8"><title>Replacing dec2flt by fast-float in core · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html">Replacing dec2flt by fast-float in core</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="238599104"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238599104" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Urgau <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238599104">(May 13 2021 at 09:20)</a>:</h4>
<p><em>Context</em>: Yesterday Alexhuszagh post a <a href="https://github.com/rust-lang/rust/issues/85198">issue</a> on the rust repository for speeding up the float parsing in the std library by improving the current dec2flt algorithm. I search online to find crate that do better parsing and found <a href="https://github.com/aldanor/fast-float-rust/">fast-float-rust</a> based on the C++ library. I post an issue to know if they have <a href="https://github.com/aldanor/fast-float-rust/issues/15">Consider integration in core and std ?</a>, they responded no. Later Alexhuszagh posted on this issue his <a href="https://github.com/aldanor/fast-float-rust/issues/15#issuecomment-840017060">5 steps</a> plan to drastically improve the current dec2flt algorithm. By talking with him on the issue I proposed to directly replace the dec2flt algorithm by the fast-float. His respond was "Sure, if the maintainers are up for that".</p>
<p><em>fast-float</em>: <a href="https://github.com/aldanor/fast-float-rust">repository</a> <a href="https://github.com/aldanor/fast-float-rust#performance">performence</a> (2-8x times faster than std) <a href="https://github.com/aldanor/fast-float-rust/issues/15#issuecomment-840054111">size</a> (important for IoT; slightly smaller with opt 2 and 3) <a href="https://arxiv.org/abs/2101.11408">academic paper</a></p>
<p>Would T-Libs considered replacing the dec2flt by fast-float algorithm or would you prefer the 5 steps plan from Alexhuszagh?</p>



<a name="238621593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238621593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238621593">(May 13 2021 at 13:35)</a>:</h4>
<p>So, two thoughts:</p>



<a name="238622565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238622565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238622565">(May 13 2021 at 13:42)</a>:</h4>
<p>fast-float-rust says it's directly based on the C++ library. Is the Rust implementation derived from the C++ code or the algorithm in the paper? Asking because the C++ code is just Apache-2.0, but the Rust code says MIT/Apache-2.0.</p>



<a name="238623023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238623023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238623023">(May 13 2021 at 13:46)</a>:</h4>
<p>If the Rust code were a derived work of the C++, it wouldn't be able to add the MIT dual license. (And the C++ code has had third-party contributions, so it isn't just the original author who would need to grant permission for that.)</p>



<a name="238623493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238623493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238623493">(May 13 2021 at 13:50)</a>:</h4>
<p>The other thought: this seems like a great idea to me, backed up by the benchmarks, but it would be nice to get confirmation of that vs the proposed modifications to dec2flt from Alexhuszagh. Since it sounds like those modifications have already been tried in an external repo, could you confirm with Alexhuszagh if they believe fast-float-rust would be the right path forward even given their proposed modifications?</p>



<a name="238623611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238623611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238623611">(May 13 2021 at 13:51)</a>:</h4>
<p>(And if integrating fast-float-rust turns out to be a challenge that takes time, we should go ahead and apply the proposed changes to dec2flt in the interim.)</p>



<a name="238623641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238623641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238623641">(May 13 2021 at 13:51)</a>:</h4>
<p><span class="user-mention" data-user-id="327095">@Urgau</span> Does that answer your question?</p>



<a name="238624493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238624493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Urgau <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238624493">(May 13 2021 at 13:58)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core/near/238622565">said</a>:</p>
<blockquote>
<p>fast-float-rust says it's directly based on the C++ library. Is the Rust implementation derived from the C++ code or the algorithm in the paper? Asking because the C++ code is just Apache-2.0, but the Rust code says MIT/Apache-2.0.</p>
</blockquote>
<p>I don't know, I will ask the maintainers of fast-float, both Rust and C++.<br>
<span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core/near/238623493">said</a>:</p>
<blockquote>
<p>The other thought: this seems like a great idea to me, backed up by the benchmarks, but it would be nice to get confirmation of that vs the proposed modifications to dec2flt from Alexhuszagh. Since it sounds like those modifications have already been tried in an external repo, could you confirm with Alexhuszagh if they believe fast-float-rust would be the right path forward even given their proposed modifications?</p>
</blockquote>
<p>Alex said in <a href="https://github.com/aldanor/fast-float-rust/issues/15#issuecomment-840017060">this</a> reply: "Ideally, we'd remove it, and replace it with your code". So yes.<br>
<span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core/near/238623641">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="327095">Urgau</span> Does that answer your question?</p>
</blockquote>
<p>Yes absolutely. Thanks you for your response.</p>



<a name="238624938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238624938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238624938">(May 13 2021 at 14:02)</a>:</h4>
<p>Please start by only asking the maintainers of the Rust code; the maintainers of the C++ code aren't responsible for downstream projects of theirs.</p>



<a name="238625019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238625019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238625019">(May 13 2021 at 14:02)</a>:</h4>
<p>(And please be diplomatic about it.)</p>



<a name="238625965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238625965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Urgau <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238625965">(May 13 2021 at 14:09)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span>  Okay, no problem.<br>
I also just saw that the C++ README <a href="https://github.com/fastfloat/fast_float#other-programming-languages">reference</a> the  Rust code as an port.</p>
<blockquote>
<p>There is a Rust port of the fast_float library called fast-float-rust.</p>
</blockquote>



<a name="238638355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238638355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238638355">(May 13 2021 at 15:37)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core/near/238623493">said</a>:</p>
<blockquote>
<p>The other thought: this seems like a great idea to me, backed up by the benchmarks, but it would be nice to get confirmation of that vs the proposed modifications to dec2flt from Alexhuszagh. Since it sounds like those modifications have already been tried in an external repo, could you confirm with Alexhuszagh if they believe fast-float-rust would be the right path forward even given their proposed modifications?</p>
</blockquote>
<p>I'm fine with either. I'm attempting to make incremental changes in the short term, but I'm more than happy if everything pans out to replace it with fast-float-rust entirely.</p>



<a name="238639117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238639117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238639117">(May 13 2021 at 15:43)</a>:</h4>
<p>My goal is merely to get float parsing to go faster. My incremental improvements are mostly to be just that: incremental. If we can get full approval to merge fast-float-rust into core and that's ok with the current maintainers (I see Hanna Kruppe retired), even better.</p>



<a name="238640352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238640352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238640352">(May 13 2021 at 15:52)</a>:</h4>
<p><span class="user-mention" data-user-id="153718">@Alexander Huszagh</span> You're confident that fast-float would be faster than your optimized version of dec2flt?</p>



<a name="238640458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238640458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238640458">(May 13 2021 at 15:53)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> Absolutely. I'm the author of lexical, and my work currently has been entirely supplanted by the Eisel-Lemire algorithm, and the Rust implementation is a fair bit faster. There's a few, isolated cases where it can be improved upon, however.</p>



<a name="238640584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238640584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238640584">(May 13 2021 at 15:54)</a>:</h4>
<p>Sounds good to me. Then yeah, assuming there's no license issue, I'd love to see fast-float-rust added, and then incrementally improved from there.</p>



<a name="238640621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238640621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238640621">(May 13 2021 at 15:54)</a>:</h4>
<p>1). Disguised fast-path cases. These are cases like <code>1.2345e30</code>, where we can get ~30% improvement in performance of these cases (without affecting other paths) with a trivial modification to float parsing.</p>



<a name="238640735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238640735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238640735">(May 13 2021 at 15:55)</a>:</h4>
<p>We should consider whether it's going to be larger in terms of code/data size, especially while it's hard to cfg out float support from libcore</p>



<a name="238640747"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238640747" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238640747">(May 13 2021 at 15:55)</a>:</h4>
<p>2). There's a few cases where the Clinger's old algorithm Bellerophon covers cases Eisel-Lemire doesn't. Since big-integer arithmetic is slow, it's a suitable fallback and fairly trivial to implement.</p>



<a name="238640767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238640767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238640767">(May 13 2021 at 15:55)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> I've done the tests: it's comparable in size for all optimization levels.</p>



<a name="238640850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238640850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238640850">(May 13 2021 at 15:56)</a>:</h4>
<p>See: <a href="https://github.com/aldanor/fast-float-rust/issues/15#issuecomment-840054111">https://github.com/aldanor/fast-float-rust/issues/15#issuecomment-840054111</a></p>



<a name="238640891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238640891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238640891">(May 13 2021 at 15:56)</a>:</h4>
<p>Great!</p>



<a name="238641128"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238641128" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238641128">(May 13 2021 at 15:59)</a>:</h4>
<p>These are a trivial smoke test for benchmarks, and what I'm basing my incremental improvements on:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="c1">// Example fast-path value.</span>
<span class="k">const</span><span class="w"> </span><span class="n">FAST_PATH</span>: <span class="kp">&amp;</span><span class="kt">str</span> <span class="o">=</span><span class="w"> </span><span class="s">"1.2345e22"</span><span class="p">;</span><span class="w"></span>
<span class="c1">// Example disguised fast-path value.</span>
<span class="k">const</span><span class="w"> </span><span class="n">DISGUISED_FAST_PATH</span>: <span class="kp">&amp;</span><span class="kt">str</span> <span class="o">=</span><span class="w"> </span><span class="s">"1.2345e30"</span><span class="p">;</span><span class="w"></span>
<span class="c1">// Example moderate path value: clearly not halfway `1 &lt;&lt; 53`.</span>
<span class="k">const</span><span class="w"> </span><span class="n">MODERATE_PATH</span>: <span class="kp">&amp;</span><span class="kt">str</span> <span class="o">=</span><span class="w"> </span><span class="s">"9007199254740992.0"</span><span class="p">;</span><span class="w"></span>
<span class="c1">// Example exactly-halfway value `(1&lt;&lt;53) + 1`.</span>
<span class="k">const</span><span class="w"> </span><span class="n">HALFWAY</span>: <span class="kp">&amp;</span><span class="kt">str</span> <span class="o">=</span><span class="w"> </span><span class="s">"9007199254740993.0"</span><span class="p">;</span><span class="w"></span>
<span class="c1">// Example large, near-halfway value.</span>
<span class="k">const</span><span class="w"> </span><span class="n">LARGE</span>: <span class="kp">&amp;</span><span class="kt">str</span> <span class="o">=</span><span class="w"> </span><span class="s">"8.988465674311580536566680e307"</span><span class="p">;</span><span class="w"></span>
<span class="c1">// Very long, near-halfway large value.</span>
<span class="k">const</span><span class="w"> </span><span class="n">LONG_LARGE</span>: <span class="kp">&amp;</span><span class="kt">str</span> <span class="o">=</span><span class="w"> </span><span class="s">"8.9884656743115805365666807213050294962762414131308158973971342756154045415486693752413698006024096935349884403114202125541629105369684531108613657287705365884742938136589844238179474556051429647415148697857438797685859063890851407391008830874765563025951597582513936655578157348020066364210154316532161708031999e+307"</span><span class="p">;</span><span class="w"></span>
<span class="c1">// Example denormal, near-halfway value.</span>
<span class="k">const</span><span class="w"> </span><span class="n">DENORMAL</span>: <span class="kp">&amp;</span><span class="kt">str</span> <span class="o">=</span><span class="w"> </span><span class="s">"8.442911973260991817129021e-309"</span><span class="p">;</span><span class="w"></span>
<span class="c1">// Very long, near-halfway, denormal value.</span>
<span class="k">const</span><span class="w"> </span><span class="n">LONG_DENORMAL</span>: <span class="kp">&amp;</span><span class="kt">str</span> <span class="o">=</span><span class="w"> </span><span class="s">"2.4703282292062327208828439643411068618252990130716238221279284125033775363510437593264991818081799618989828234772285886546332835517796989819938739800539093906315035659515570226392290858392449105184435931802849936536152500319370457678249219365623669863658480757001585769269903706311928279558551332927834338409351978015531246597263579574622766465272827220056374006485499977096599470454020828166226237857393450736339007967761930577506740176324673600968951340535537458516661134223766678604162159680461914467291840300530057530849048765391711386591646239524912623653881879636239373280423891018672348497668235089863388587925628302755995657524455507255189313690836254779186948667994968324049705821028513185451396213837722826145437693412532098591327667236328125001e-324"</span><span class="p">;</span><span class="w"></span>
</code></pre></div>



<a name="238641437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238641437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238641437">(May 13 2021 at 16:01)</a>:</h4>
<p>These cover all common pitfalls in terms of performance for float parsing:<br>
1). Fast path cases, where both the exponent and the significant digits can be represented as native integers.<br>
2). Disguised fast path cases, where we can move powers of 10 from the exponent to the significant digits.<br>
3). Moderate path cases, where we force Eisel-Lemire or Bellerophon algorithms.<br>
4). Halfway cases, which can force slow path algorithms in bad cases.<br>
5). Large and denormal, which do the same thing, but test implementations with large and small powers.<br>
6). Long variants of these, which should force slow path (arbitrary-precision) algorithms.</p>



<a name="238642051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238642051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238642051">(May 13 2021 at 16:03)</a>:</h4>
<p>In the <code>LARGE</code> case,  an optimized version of Bellerophon is still faster than fast-float-rust, since it is forced to go to the slow algorithms.<br>
In the <code>DISGUISED_FAST_PATH</code> case, we can improve the performance ~30% with trivial improvements to the algorithm.</p>
<p>A poorly optimized version of the Bellerophon algorithm is ~20x as fast as fast-float-rust, so we should definitely consider it.</p>



<a name="238642544"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238642544" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238642544">(May 13 2021 at 16:07)</a>:</h4>
<p>Neither of these changes should affect binary size (the disguised fast path case definitely does not), and Bellerophon modifications might introduce a slightly large binary size (I'd have to test), but can trivially be minimized to a very small algorithm:</p>
<p>1). A struct with a 64-bit mantissa, and 16-bit exponent (stored as an i32 likely)<br>
2). A 64-bit multiplication algorithm, slightly different than the one used in Eisel-Lemire.<br>
3). An algorithm to normalize floats, which is essentially the <code>ctlz</code>instruction and then a bitshift.<br>
4). A trivial approach to count errors. This is like 5 lines of code.<br>
5). A trivial number of bitshifts and bitmasks to ensure we round-nearest, tie-even.</p>
<p>This reason these differences occur is because the Bellerophon algorithm and the Eisel-Lemire algorithm don't have perfect overlap in cases they can unambiguously detect. The Eisel-Lemire algorithm does 2 passes if there are truncated digits for <code>mantissa</code> and <code>mantissa+1</code> to ensure there are no halfway rounding cases, and if the first pass fails, we can fallback to Bellerophon.</p>



<a name="238642742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238642742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238642742">(May 13 2021 at 16:08)</a>:</h4>
<p>In short, I'm entirely on board, and have a few small additions to suggest for certain corner cases.</p>



<a name="238681896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238681896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238681896">(May 13 2021 at 21:10)</a>:</h4>
<p><span class="user-mention" data-user-id="153718">@Alexander Huszagh (He/Him)</span> Will your proposed changes increase the correctness of dec2float?</p>



<a name="238689382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238689382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238689382">(May 13 2021 at 22:16)</a>:</h4>
<p><span class="user-mention" data-user-id="281757">@Jubilee</span> It won't affect the correctness (both will be correct), but it will increase performance for certain cases (the former which is relatively common, the latter which is fairly rare) noticeably.</p>
<p>Basically, Eisel-Lemire is a very fast algorithm that occurs if the fast-path (native floats) don't work, and otherwise it falls back to a slow-path algorithm. Bellerophon only would then be used if Eisel-Lemire fails on the first pass, but before the slow path is used.</p>
<p>The slow path <strong>always</strong> works, even on trivial floats. It's just very slow, so it's typically not used unless needed.</p>
<p>They're also relatively simple to implement. The former just got merged into fast-float-rust, although I'm not sure if the latter will.</p>



<a name="238690901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238690901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238690901">(May 13 2021 at 22:31)</a>:</h4>
<p>The last change is handy (for a small percentage of floats, it has a major difference in performance), but they're very rare, so they'd have to be specifically designed for slow performance to affect the speed of float parsing in any real world example. The former is much more important, and is about the be merged, so we shouldn't have any issues.</p>
<p>For 3 examples of floats that might be classified by Eisel-Lemire or Bellerophon, we have:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="s">"9007199254740992000e-3"</span><span class="w">   </span><span class="c1">// Exactly represented, (1&lt;&lt;53)</span>
<span class="s">"9007199254740993000e-3"</span><span class="w">   </span><span class="c1">// Halfway, ((1&lt;&lt;53)+1)</span>
<span class="s">"9007199254740994000e-3"</span><span class="w">   </span><span class="c1">// Exactly represented, ((1&lt;&lt;53)+2)</span>
</code></pre></div>
<p>Eisel-Lemire cannot determine if any of these are correct, while Bellerophon can correctly round 1 and 3. In these case, Bellerophon is ~20-30x faster than Eisel-Lemire, but this probably affects like 0.1% of all floats, and very few real-world examples.</p>



<a name="238692476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238692476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238692476">(May 13 2021 at 22:47)</a>:</h4>
<p>The full implementation of a rather unoptimized version can be found here, and the only routines outside of <a href="https://github.com/Alexhuszagh/rust-dec2flt/blob/moderate/src/dec2flt/algorithm.rs#L168-L215">here</a> are <code>normalize</code> and <code>mul</code>. <code>mul</code> is just a 64-bit multiplication that rounds-up if the lower 64-bits are above or are halfway, and takes the high 64-bits. <code>normalize</code> is just a ctlz operation that adjusts both the binary exponent and the significant digits.</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">normalize</span><span class="p">(</span><span class="n">fp</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="n">Fp</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">     </span><span class="kd">let</span><span class="w"> </span><span class="n">ctlz</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">fp</span><span class="p">.</span><span class="n">mant</span><span class="p">.</span><span class="n">leading_zeros</span><span class="p">();</span><span class="w"></span>
<span class="w">     </span><span class="n">fp</span><span class="p">.</span><span class="n">mant</span><span class="w"> </span><span class="o">&lt;&lt;=</span><span class="w"> </span><span class="n">ctlz</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="n">fp</span><span class="p">.</span><span class="n">exp</span><span class="w"> </span><span class="o">-=</span><span class="w"> </span><span class="n">ctlz</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">i32</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>And that's it. The <code>power_of_ten</code> is also shared with fast-float-rust.</p>
<p>If we want to get rid of denormal cases, we can remove ~75% of the code for the algorithm.</p>



<a name="238692598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238692598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238692598">(May 13 2021 at 22:48)</a>:</h4>
<p>The full <code>mul</code> implementation can be found here (it's already in Rust core):<br>
<a href="https://github.com/Alexhuszagh/rust-dec2flt/blob/ad4596cc85ee3647cb20d594651a6061b16ca6a9/src/diy_float.rs#L15-L29">https://github.com/Alexhuszagh/rust-dec2flt/blob/ad4596cc85ee3647cb20d594651a6061b16ca6a9/src/diy_float.rs#L15-L29</a></p>



<a name="238730640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238730640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Urgau <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238730640">(May 14 2021 at 07:45)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> Just to come to your legal concern, I have receive confirmation by the owner of the crate that the crate is entirely based on the C++ code.<br>
In this <a href="https://github.com/aldanor/fast-float-rust/issues/15#issuecomment-840649609">comment </a>, he propose to "make the original library Apache2/MIT" or "make this crate Apache2-only" (like the C++ code). Which of these 2 solutions do you think would solve the licensing problem?</p>



<a name="238746136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238746136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238746136">(May 14 2021 at 10:27)</a>:</h4>
<p>So, the former would be the only way the code could be added to the Rust standard library, but such a change would require permission from every contributor to the original library (not just the primary author).</p>



<a name="238746249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238746249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238746249">(May 14 2021 at 10:28)</a>:</h4>
<p>(You can safely skip requesting permission from anyone who has only contributed to the readme or something else other than the C++ code.)</p>



<a name="238775070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238775070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238775070">(May 14 2021 at 14:26)</a>:</h4>
<p>So looking for who needs to agree to accept relicensing in the original C++ implementation, there are currently 9 contributors.</p>
<p>Lemire is the main author, and has said "+1".<br>
Timkpaine only added a compiler <a href="https://github.com/fastfloat/fast_float/commit/48d30f789beae7dd6af6ead58854d42b3a808db1">flag</a> for emscripten, which is irrelevant here.<br>
eugenegfff added support for signalling <a href="https://github.com/fastfloat/fast_float/commit/76dec80fbd574c69685c147a0d83d6cc8aaaa9a1">NaNs</a>, which fast-float-rust does not use.<br>
0xfloatus fixed the <a href="https://github.com/fastfloat/fast_float/commit/82ea4af1079a106c3f1397746ead966fdf5c11ac">README</a><br>
nealrichardson added a compiler <a href="https://github.com/fastfloat/fast_float/commit/ca0a4646e91e1485e69aea985b53bb22d0f819b1">flag</a> for Solaris, also irrelevant here.<br>
georg-emg <a href="https://github.com/fastfloat/fast_float/commit/0d33df55baf1847ff025a58afd8de0ecb4ff7511">added</a> <a href="https://github.com/fastfloat/fast_float/commit/dfa304a698a19c68e5d35894b076b35b28b714e2">cmake</a> <a href="https://github.com/fastfloat/fast_float/commit/f1681745e47951a35fb823e5438373e1f7b7843b">targets</a>, although the second commit may contain relevant code for truncated 0s.<br>
kitisreal only changed <a href="https://github.com/fastfloat/fast_float/commit/68633178d56807585a455a2134d2807f425cfc96">inlining</a></p>
<p>So it's just biojppm and maybe georg-emg that need to agree to a license change, in addition to lemire, if this was based off an earlier version.</p>
<p>If not, we need 2 more people who added compiler flags for endian-aware stuff.</p>



<a name="238777401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238777401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238777401">(May 14 2021 at 14:40)</a>:</h4>
<p>Since the vast majority of the commits were in January for fast-float-rust, and nothing that changes the actual code has been done since, this would only be kitaisreal and biojppm who is relevant.</p>



<a name="238921022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238921022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238921022">(May 15 2021 at 19:47)</a>:</h4>
<p>Ok we've made significant progress on this:</p>
<p>1). Lemire has emailed biojppm, the only person we need approval from for merging.<br>
2). I've merged in the optimization for disguised fast-path cases.<br>
3). I've fixed tests for 32-bit architectures.<br>
4). I've done comprehensive tests on the following platforms, all of which demonstrate correctness:</p>
<ul>
<li>powerpc-unknown-linux-gnu</li>
<li>armv7-unknown-linux-gnueabihf</li>
<li>x86_64-unknown-linux-gnu</li>
</ul>



<a name="238921235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238921235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238921235">(May 15 2021 at 19:50)</a>:</h4>
<p>I'll be running tests on all the Tier 1 targets today, and a few more Tier 2 targets just in case. The correctness <a href="https://github.com/Alexhuszagh/fast-float-rust/tree/comprehensive/data">checks</a> use Rust's built-in tests, along with Golang's tests, and a few specialized cases. No errors have been detected. We've also confirmed the accepted float syntax matches nightly (with the special float fixes for case-sensitivity).</p>
<p>I will be checking:</p>
<ul>
<li>aarch64-unknown-linux-gnu</li>
<li>i686-unknown-linux-gnu</li>
<li>arm-unknown-linux-gnueabihf</li>
<li>mips-unknown-linux-gnu</li>
<li>mips64el-unknown-linux-gnuabi64</li>
<li>s390x-unknown-linux-gnu</li>
<li>riscv64gc-unknown-linux-gnu</li>
</ul>
<p>I'll get back to you when all these tests pass in like 2 days, but everything should work :D.</p>



<a name="238921414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238921414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238921414">(May 15 2021 at 19:54)</a>:</h4>
<p>There's also been talk about adding a <code>from_parts</code> method for <code>f32</code> and <code>f64</code>, that would take a signature as follows:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">impl</span><span class="w"> </span><span class="kt">f32</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">from_parts</span><span class="p">(</span><span class="n">integral</span>: <span class="kp">&amp;</span><span class="kt">str</span><span class="p">,</span><span class="w"> </span><span class="n">fractional</span>: <span class="kp">&amp;</span><span class="kt">str</span><span class="p">,</span><span class="w"> </span><span class="n">exponent</span>: <span class="kt">i64</span><span class="p">,</span><span class="w"> </span><span class="n">negative</span>: <span class="kt">bool</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">f32</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>This would be very handy in parser implementations (and would have almost entirely code re-use), since it would allow parsing formats like JSON and TOML which do not have the same syntax as Rust floats (as well as basically every other programming language).</p>
<p>Obviously, this would need to go through an RFC process, and is beyond the scope of this discussion.</p>



<a name="238988013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238988013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Urgau <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238988013">(May 16 2021 at 15:53)</a>:</h4>
<p>My <a href="https://github.com/fastfloat/fast_float/pull/70">pull request</a> for dual licensing the C++ <a href="https://github.com/fastfloat/fast_float/">fast_float</a> with MIT/Apache has been merged. We're now also go to go with licensing. <span aria-label="tada" class="emoji emoji-1f389" role="img" title="tada">:tada:</span></p>



<a name="238995106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238995106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238995106">(May 16 2021 at 17:51)</a>:</h4>
<p>Nicely done!</p>



<a name="238999863"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/238999863" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#238999863">(May 16 2021 at 19:15)</a>:</h4>
<p>I've expanded my tests to:</p>
<ul>
<li>powerpc-unknown-linux-gnu</li>
<li>armv7-unknown-linux-gnueabihf</li>
<li>x86_64-unknown-linux-gnu</li>
<li>s390x-unknown-linux-gnu</li>
<li>mips64el-unknown-linux-gnuabi64</li>
<li>mips-unknown-linux-gnu</li>
<li>arm-unknown-linux-gnueabihf</li>
<li>i686-unknown-linux-gnu</li>
<li>aarch64-unknown-linux-gnu</li>
<li>powerpc64le-unknown-linux-gnu</li>
<li>armv7-unknown-linux-gnueabihf</li>
<li>riscv64gc-unknown-linux-gnu</li>
</ul>
<p>That should effectively be every Tier-1 and Tier-2 target.</p>



<a name="239000790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/239000790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#239000790">(May 16 2021 at 19:32)</a>:</h4>
<p>Hmm, I'd expect powerpc64le-unknown-linux-gnu to be in the list, instead of/in addition to powerpc-unknown-linux-gnu</p>



<a name="239001878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/239001878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#239001878">(May 16 2021 at 19:52)</a>:</h4>
<p><span class="user-mention" data-user-id="229517">@Jacob Lifshay</span> It should be, that was a typo (powerpc-unknown-linux-gnu was duplicated). Thank you.</p>



<a name="239001923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/239001923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#239001923">(May 16 2021 at 19:53)</a>:</h4>
<p>x86_64-unknown-linux-gnu is also duplicated</p>



<a name="239008843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/239008843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#239008843">(May 16 2021 at 21:49)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">targets</span><span class="p">.</span><span class="n">sort</span><span class="p">();</span><span class="w"></span>
<span class="n">targets</span><span class="p">.</span><span class="n">dedup</span><span class="p">();</span><span class="w"></span>
</code></pre></div>



<a name="239008854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/239008854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#239008854">(May 16 2021 at 21:49)</a>:</h4>
<p><span aria-label="wink" class="emoji emoji-1f609" role="img" title="wink">:wink:</span></p>



<a name="239016839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/239016839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#239016839">(May 17 2021 at 00:05)</a>:</h4>
<p><span class="user-mention silent" data-user-id="138448">cuviper</span> <a href="#narrow/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core/near/239008843">said</a>:</p>
<blockquote>
<p><div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">targets</span><span class="p">.</span><span class="n">sort</span><span class="p">();</span><span class="w"></span>
<span class="n">targets</span><span class="p">.</span><span class="n">dedup</span><span class="p">();</span><span class="w"></span>
</code></pre></div><br>
</p>
</blockquote>
<p>;) Whoooops.</p>



<a name="244493183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/244493183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#244493183">(Jun 30 2021 at 21:51)</a>:</h4>
<p>This has been tentatively implemented and submitted as a PR <a href="https://github.com/rust-lang/rust/pull/86761">here</a>.</p>



<a name="244884971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/244884971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#244884971">(Jul 05 2021 at 00:42)</a>:</h4>
<p>Ok further updates on this <a href="https://github.com/rust-lang/rust/pull/86761">PR</a>:</p>
<ol>
<li>Almost all unsafety has been removed, and all unsafety can be provably correct.</li>
<li>The implementation can be shown trivially to not panic either.</li>
<li>Benchmarks have been run, showing excellent <a href="https://github.com/rust-lang/rust/pull/86761#issuecomment-873695763">performance</a>.</li>
<li>The replaced unsafe functions with safe implementations generate identical <a href="https://github.com/Alexhuszagh/fast-float-asm">ASM</a> in most cases, sometimes faster.</li>
<li>I've used <a href="https://github.com/rust-lang/miri-test-libstd">Miri</a> to test the core library for the new dec2flt implementation: everything passes.</li>
<li>All errors in <a href="https://github.com/Alexhuszagh/rust/blob/master/src/etc/test-float-parse/runtests.py">runtests.py</a> for comprehensive float tests have been patched.</li>
<li>The float library is more correct than before, handling floats with large numbers of digits and subnormal floats without erroring. This fixes numerous outstanding issues.</li>
<li>Regression tests for the affected issues have been added.</li>
<li>Compiler workarounds for unparseable float literals have been removed, as they can no longer occur.</li>
<li>Extensive documentation has been added to ensure the code is maintainable and correct.</li>
<li>The author of the paper describing the new algorithms has reviewed the code numerous times, and said <a href="https://github.com/aldanor/fast-float-rust/issues/15#issuecomment-873640634">the code looks great</a>.</li>
<li>Documentation for control-flow paths that may be non-obvious have also been added, including feedback from others who reviewed the library and found parts not obvious immediately.</li>
<li>References to the library, as well as extensive documentation describing the algorithms have been added, so non-experts should be able to understand the code, including for how constants were <a href="https://github.com/Alexhuszagh/rust/blob/73c939107703641be9173d7cf66209f87d10245c/library/core/src/num/dec2flt/float.rs#L35-L52">generated</a>.</li>
<li>The binary sizes are comparable or smaller than the previous implementation.</li>
</ol>
<p>I believe the PR is in a state where it's ready or decently close to ready to merge: any additional feedback would be greatly appreciated.</p>



<a name="246341014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/246341014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Urgau <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#246341014">(Jul 17 2021 at 19:54)</a>:</h4>
<p>After a crater run that found no regression, the <a href="https://github.com/rust-lang/rust/pull/86761">pull-request</a> has been <a href="https://github.com/rust-lang/rust/pull/86761#issuecomment-881914858">merged</a> <span aria-label="tada" class="emoji emoji-1f389" role="img" title="tada">:tada:</span></p>



<a name="246351678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/246351678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#246351678">(Jul 18 2021 at 00:31)</a>:</h4>
<p><span class="user-mention silent" data-user-id="327095">Urgau</span> <a href="#narrow/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core/near/246341014">said</a>:</p>
<blockquote>
<p>After a crater run that found no regression, the <a href="https://github.com/rust-lang/rust/pull/86761">pull-request</a> has been <a href="https://github.com/rust-lang/rust/pull/86761#issuecomment-881914858">merged</a> <span aria-label="tada" class="emoji emoji-1f389" role="img" title="tada">:tada:</span></p>
</blockquote>
<p>Esteban also had a great suggestion now that we can parse float literals: it might be worthwhile having compiler warnings if the value provided by the user for literals substantially differs from the actual value. The classic example would be:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">9007199254740992.0</span><span class="p">;</span><span class="w">  </span><span class="c1">// 1 &lt;&lt; 53</span>
<span class="kd">let</span><span class="w"> </span><span class="n">b_h</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">9007199254740993.0</span><span class="w"> </span><span class="c1">// (1&lt;&lt;53) + 1</span>
<span class="kd">let</span><span class="w"> </span><span class="n">b</span><span class="o">+</span><span class="n">u</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">9007199254740994.0</span><span class="w"> </span><span class="c1">// (1&lt;&lt;53) + 2</span>
</code></pre></div>
<p>In the <code>b_h</code> case (or, <code>b+h</code>, signifying it's a halfway point between <code>b</code> and <code>b+u</code>), we would truncate the value down to <code>9007199254740992.0</code>, which is likely not what the developer wanted (obviously, these warnings could be silenced).</p>
<p>It would be doable to implement this, since we can use the Dragon4 serializing algorithm with format precision control to see if there's any difference in the significant digits.</p>



<a name="246351752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/246351752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Huszagh (He/Him) <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#246351752">(Jul 18 2021 at 00:33)</a>:</h4>
<p>For example, if someone inputs '0.1', obviously we wouldn't warn about <code>0.1000000000000000055511151</code>, since <code>0.1</code> is the nearest possible float with 1 significant digit. However, the above case would be a good example to the contrary. It might be a good usability feature, since it avoids correctness issues for literals at compile time (a good alternative to hexadecimal floats).</p>



<a name="246354585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Replacing%20dec2flt%20by%20fast-float%20in%20core/near/246354585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Replacing.20dec2flt.20by.20fast-float.20in.20core.html#246354585">(Jul 18 2021 at 02:03)</a>:</h4>
<p>i'm in favor of this but genuinely don't think it's an alternative to hex floats</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>